﻿using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Protocol;
using System;

namespace SuperX.SuperSocket.Socket.Transfer.Server
{
    public class TransferSession : TransferSession<TransferSession>
    {
        public TransferServer TransferServer { get; set; }
        private object lockobj = new object();
        private FileTransferServerEngine _fileTransferServerEngine;

        public FileTransferServerEngine FileTransferEngine
        {
            get
            {
                if (_fileTransferServerEngine == null)
                {
                    lock (lockobj)
                    {
                        if (_fileTransferServerEngine == null)
                        {
                            _fileTransferServerEngine = new FileTransferServerEngine(this);
                        }
                    }
                }
                return _fileTransferServerEngine;
            }
        }

        protected override void OnSessionClosed(CloseReason reason)
        {
            if (_fileTransferServerEngine != null)
                _fileTransferServerEngine.Dispose();
            base.OnSessionClosed(reason);
        }
    }

    public class TransferSession<TWebSocketSession> : AppSession<TWebSocketSession, BinaryRequestInfo>,
        IAppSession, ISessionBase where TWebSocketSession : TransferSession<TWebSocketSession>, new()
    {
    }
}